package com.syq.dao.impl;

import com.syq.dao.MiddleDao;
import com.syq.util.DBUtils;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

public class MiddleDaoImpl extends DBUtils implements MiddleDao {
    @Override
    public int addMiddle(int roleId, String[] ids) {
        int k = 0;
        try {
            String sql = "insert into middle values(null,?,?)";
            //批量新增
            pps = getPps(sql);
            for( String id :ids) {
                pps.setInt(1,roleId);
                pps.setString(2,id);
                pps.addBatch();
            }
            pps.executeBatch();
            k = 1;
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            closeAll();
        }
        return k;
    }

    @Override
    public int delMiddle(int roleId) {
        String sql = "delete from middle where roleid="+roleId;
        int update = update(sql, null);
        return update;
    }
}
